package com.mc.general;

import java.util.Iterator;

public class Bag<Item> implements Iterable<Item>{
	
	private Node first;
	private int N;	
	public void add(Item item){
		Node old = this.first;
		first = new Node();
		first.item = item;
		first.next = old;
		N++;
	}
	
	public int size(){
		return N;
	}
	public boolean isEmpty(){
		return N==0;
	}
	private class Node{
		Item item;
		Node next;
	}
	@Override
	public Iterator<Item> iterator() {
		return new ListIterator();
	}
	
	private class ListIterator implements Iterator<Item>{
		private Node current = first;
		@Override
		public boolean hasNext() {
			return current!=null;
		}
		@Override
		public Item next() {
			Item item = current.item;
			current = current.next;
			return item;
		}
		@Override
		public void remove() {
			// TODO Auto-generated method stub
		}
	}
}
